package com.example.novelweb.controller;


import com.example.novelweb.common.BaseResponse;
import com.example.novelweb.common.ErrorCode;
import com.example.novelweb.common.ResultUtils;
import com.example.novelweb.exception.BusinessException;
import com.example.novelweb.exception.ThrowUtils;
import com.example.novelweb.model.entity.Collect;
import com.example.novelweb.model.vo.NovelVO;
import com.example.novelweb.model.vo.UserVO;
import com.example.novelweb.service.CollectService;
import com.example.novelweb.utils.UserUtils;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/collect")
public class CollectController {

  @Resource
  CollectService collectService;

  @ApiImplicitParam(name = "Authorization", value = "Authorization",required = true, dataType = "String",paramType="header")
  @PostMapping("/add")
  public BaseResponse<Boolean> addCollect(@RequestParam("novelId")Long novelId, HttpServletRequest httpServletRequest) {
    ThrowUtils.throwIf(novelId == null || novelId <= 0, ErrorCode.PARAMS_ERROR,"param id is null or invalid");
    return collectService.add(novelId);
  }

  @ApiImplicitParam(name = "Authorization", value = "Authorization",required = true, dataType = "String",paramType="header")
  @PostMapping("/del")
  public BaseResponse<Boolean> delCollect(@RequestParam("novelId") Long novelId,HttpServletRequest httpServletRequest) {
    ThrowUtils.throwIf(novelId == null || novelId <= 0, ErrorCode.PARAMS_ERROR,"param id is null or invalid");
    return collectService.del(novelId);
  }


  @GetMapping("/list")
  public BaseResponse<List<NovelVO>> listCollectByUserId(Long userId,HttpServletRequest httpServletRequest) {
    ThrowUtils.throwIf(userId == null || userId <= 0, ErrorCode.PARAMS_ERROR,"param id is null or invalid");
    return collectService.getUserCollects(userId);
  }



}
